﻿package engine;

import java.awt.*;
import java.util.*;

import javax.swing.*;

import constants.*;

import person.*;

public class AvartaEngine {
	private static AvartaEngine avartaEngine = new AvartaEngine();
	private PersonRecorder personRecorder;
	private Image avartaImage;

	private AvartaEngine() {
	}

	public static AvartaEngine getAvartaEngine() {
		return avartaEngine;
	}

	public PersonRecorder getPersonRecorder() {
		return personRecorder;
	}

	public void setPersonRecorder(PersonRecorder personRecorder) {
		this.personRecorder = personRecorder;
	}

	public Image getAvartaImage() {
		return avartaImage;
	}

	public void setAvartaImage(Image avartaImage) {
		this.avartaImage = avartaImage;
	}

	public void setAvartaImageArray(PersonRecorder personRecorder) {
		Person person = personRecorder.getPerson();
		PersonInfo personInfo = personRecorder.getPersonInfoArray().get(0);
		String imgName = "";

		imgName += person.getSex().toString() + "_"; // 성별

		if (personInfo.getNumOfBMI() <= 18) { // 마름
			imgName += Constants.BODY_TYPE.SKINNY.toString();
		} else if (personInfo.getNumOfBMI() <= 23 && personInfo.getNumOfBMI() > 18) { // 표준
			imgName += Constants.BODY_TYPE.NORMAL.toString();
		} else if (personInfo.getNumOfBMI() <= 25 && personInfo.getNumOfBMI() > 23) { // 과체중
			imgName += Constants.BODY_TYPE.LITTLE_FAT.toString();
		} else if (personInfo.getNumOfBMI() <= 30 && personInfo.getNumOfBMI() > 25) { // 비만증
			imgName += Constants.BODY_TYPE.FAT.toString();
		} else if (personInfo.getNumOfBMI() > 30) { // 병적비만
			imgName += Constants.BODY_TYPE.VERY_FAT.toString();
		}
		avartaImage = new ImageIcon("img/" + imgName + ".jpg").getImage();

	}

	public int getRunningRate(int speed, int time) {
		int starImgCount = 0;

		if (speed * time <= 50) {
			starImgCount = 1;
		} else if (speed * time <= 100 && speed * time > 50) {
			starImgCount = 2;
		} else if (speed * time <= 150 && speed * time > 100) {
			starImgCount = 3;
		} else if (speed * time <= 200 && speed * time > 150) {
			starImgCount = 4;
		} else if (speed * time <= 250 && speed * time > 200) {
			starImgCount = 5;
		} else if (speed * time > 250) {
			starImgCount = 6;
		}

		return starImgCount;
	}
	
	public int getArmRate(int weight, int count) {
		int starImgCount = 0;
		
		if (weight * count <= 50) {
			starImgCount = 1;
		} else if (weight * count <= 100 && weight * count > 50) {
			starImgCount = 2;
		} else if (weight * count <= 150 && weight * count > 100) {
			starImgCount = 3;
		} else if (weight * count <= 200 && weight * count > 150) {
			starImgCount = 4;
		} else if (weight * count <= 250 && weight * count > 200) {
			starImgCount = 5;
		} else if (weight * count > 250) {
			starImgCount = 6;
		}
		
		return starImgCount;
	}
	
	public int getLegRate(int weight, int count) {
		int starImgCount = 0;
		
		if (weight * count <= 100) {
			starImgCount = 1;
		} else if (weight * count <= 200 && weight * count > 100) {
			starImgCount = 2;
		} else if (weight * count <= 300 && weight * count > 200) {
			starImgCount = 3;
		} else if (weight * count <= 400 && weight * count > 300) {
			starImgCount = 4;
		} else if (weight * count <= 500 && weight * count > 400) {
			starImgCount = 5;
		} else if (weight * count > 500) {
			starImgCount = 6;
		}
		
		return starImgCount;
	}
	
	public int getABSRate(int count) {
		int starImgCount = 0;
		
		if (count <= 20) {
			starImgCount = 1;
		} else if (count <= 40 && count > 20) {
			starImgCount = 2;
		} else if (count <= 60 && count > 40) {
			starImgCount = 3;
		} else if (count <= 80 && count > 60) {
			starImgCount = 4;
		} else if (count <= 100 && count > 80) {
			starImgCount = 5;
		} else if (count > 100) {
			starImgCount = 6;
		}
		
		return starImgCount;
	}

}
